<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>充值订单列表</title>
    <script type="text/javascript" src="js/jquery-1.11.3.js"></script>
    <link href="css/orderlist.css" rel="stylesheet" type="text/css" />
  </head>

  <body>
    <div class="miandiv">
      <div class="title">
        <ul>
          <li>订单号</li>
          <li>金额</li>
          <li>欢乐豆</li>
          <li>时间</li>
          <li>状态</li>
        </ul>
      </div>
      <div class="list">
        <ul>
          <li title="45645645645646464646546464564">
            45645645645646464646546464564
          </li>
          <li title="123456">123456</li>
          <li title="12345600">12345600</li>
          <li title="2017-1-12 15:45:52">2017-1-12 15:45:52</li>
          <li title="去支付"><a>去支付</a></li>
        </ul>
      </div>
    </div>
  </body>
  <script>
    /*
  $(function () {
    $(window.parent)[0].setiframeHight($("body").height());
  });
  */
    $(function () {
      $(".list").empty();
      //查询订单记录的接口
      queryORderList();
    });

    //查询充值订单列表
    function queryORderList() {
      //获取当前登录用户id
      var uid = localStorage.getItem("uid");

      $.ajax({
        type: "post",
        url: "http://localhost:8080/order/list",
        data: {
          uid: uid,
        },
        success: function (data) {
          if (data.length == 0) {
            var html =
              ' <ul style="display: flex; width: 100%; height: 80px"> <li style="width: 100%;height: 100%;font-size: 26px;text-align: center;  line-height: 80px;">暂无记录</li></ul>';
            $(".list").append(html);
          } else {
            //data -> 记录列表
            //for -> data -> <tr></tr> -> <tbody>
            for (var i = 0; i < data.length; i++) {
              //从data数组中取出第i条记录
              var item = data[i];

              var html =
                " <ul>" +
                '<li title="' +
                item.orderId +
                '">' +
                item.orderId +
                "</li>" +
                '<li title="' +
                item.money +
                '">' +
                item.money +
                "</li>" +
                '<li title="' +
                item.beanNumber +
                '">' +
                item.beanNumber +
                "</li>" +
                '<li title="' +
                item.createTime +
                '">' +
                item.createTime +
                "</li>" +
                '<li title="' +
                (item.status == 1 ? "已支付" : "去支付") +
                '">' +
                (item.status == 1
                  ? "已支付"
                  : "<a onclick=\"goPay('" + item.orderId + "')\">去支付</a>") +
                "</li>" +
                "</ul>";

              $(".list").append(html);
            }
          }
          $(window.parent)[0].setiframeHight($("body").height());
        },
      });
    }

    /**
     * 去支付
     */
    var orderId = null;
    function goPay(orderid) {
      orderId = orderid;
      //alert("去支付！" + orderid);

      //弹出一个支付成功的弹出框，让用户支付完成后点击
      $(window.parent)[0].openQuery(orderId);

      //打开一个新页签，进行支付宝支付
      window.open("http://localhost:8080/order/pay?orderId=" + orderid);
    }
  </script>
</html>
